package my.algorithms.mcorrea;

import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author mcorrea
 */
public class FindFirstNonRepeated {

	
	public static void main(String args[]){
		System.out.println(firsNonRepeated("interview"));
		System.out.println(firsNonRepeated("racecar"));
	
	}
	
	public static Character firsNonRepeated(String str){
		Map<Character, Integer> counts = new HashMap<Character, Integer>();
		
		for(Character c: str.toCharArray()){
			if(counts.get(c)!=null){
				counts.put(c,counts.get(c)+1);
			}else{
				counts.put(c,1);
			}
		}
		
		for(Character c: str.toCharArray()){
			if(counts.get(c) == 1)return c;
		}
		
		return null;
	}
	
	
}
